<?php

class myValidatorString extends sfValidatorBase
{
  protected function configure($options = array(), $messages = array())
  {
    parent::configure($options, $messages);
    $this->addMessage('my_error', '"%value%" caused an error.');
    $this->addOption('my_error'); 
    // your validator configuration here
  }

  protected function doClean($value)
  {
    parent::doClean($value); 
    // Your validator logic here
    if ($this->hasOption('my_error'))
    {
      throw new sfValidatorError($this, 'my_error',  array('value' => $value, 'my_error' => $this->getOption('my_error'))); 
    }

    return $value;
  }
}
?>